#include "HtmlParser.h"
#include <boost/regex.hpp>
#include <iterator>
#include <sstream>
#include <fstream>
#include <sstream>
#include <string>
#include <iterator>
#include <boost/regex.hpp>
#include <fstream>
#include <iostream>

using namespace boost;

HtmlParser::~HtmlParser(void)
{
}


string HtmlParser::getBody()
{
    boost::cmatch what;
    //regex expression("body.*\\w.*");//(\\s+[\\s\\S]*?)?>[\\s\\S]*<\\/body>");
    regex expression("<(BODY|body)(\\s+[\\s\\S]*?)?>[\\s\\S]*<\\/(BODY|body)>",regex::icase | regex::perl);
    if(regex_search((char*)m_sHtml.c_str(), what, expression))
    {
        for(int i=0;i<=what.size();i++)   
        {
             //cout<<"str :"<<what[i].str()<<endl;
            
             }
    }
    else
    {
        cout<<"Error Input getBody"<<endl;
    }

    m_sHtml = what[0];
    return m_sHtml;
}

string HtmlParser::removeScript()
{
  //  regex expression("<script((\\.|\\n)*?)\\<\\/script>");
    
    regex expression("<script[^>]*>[\\s\\S]*?</script>");
    
   
    std::ostringstream t(std::ios::out | std::ios::binary);
    std::ostream_iterator<char, char> oi(t);
    boost::regex_replace(oi,m_sHtml.begin(),m_sHtml.end(),expression,"ddd",boost::match_default | boost::format_all);
   //  std::string s(t.str());
   
   m_sHtml = t.str();
     
    return m_sHtml;    
}